//
//  SQLQueries.m
//  ExchangeClient
//
//  Created by Антон on 03.12.12.
//  Copyright (c) 2012 Сураева Яна. All rights reserved.
//

#import "SQLQueries.h"

@implementation SQLQueries
+(NSString*) insertFolder: (Folder*)folder{
    NSString *query=[NSString stringWithFormat:@"INSERT INTO users(name, idFolfer) VALUES ('%@', '%@')", folder.displayName, folder.folderID];
    return query;
}

+(NSString*) deleteFolder: (Folder*)folder{
    NSString *query=[[@"DELETE FROM users WHERE name='" stringByAppendingString:folder.displayName]stringByAppendingString:@"'"];
    return query;
}



+(NSString*) selectFolder{
    return @"SELECT name FROM users";
}

+(NSString*) deleteAllFolders{
    return @"DELETE FROM \"main\".\"users\"";
}

+(NSString*) deleteAllMails{
    return @"DELETE FROM \"main\".\"docs\"";
}

+(NSString*) insertMail: (Mail*)mail{
    NSString *query=[NSString stringWithFormat:@"INSERT INTO docs(userName, docName, subject, date, bodyType, sender, body) VALUES ('%@','%@','%@', '%@','%@','%@', '%@')",mail.parentFolderID, mail.itemID, mail.subject, mail.date, mail.bodyType, [mail.sender valueForKey:@"Name"], mail.attachments];
           
    
    return query;
    
}
+(NSString*) deleteMail: (Mail*)mail{
    NSString *query=[NSString stringWithFormat:@"DELETE FROM docs WHERE docName='%@' AND userName='%@'",mail.date,mail.parentFolderID];
    return query;
}
+(NSString*) selectMail: (Mail*)mail{
    NSString *query=[[@"SELECT docName FROM docs WHERE userName =\"" stringByAppendingString:mail.parentFolderID]stringByAppendingString:@"\""];
    return query;
}

+(NSString*) insertAttach: (Attach*)attach{
    NSString *query=[NSString stringWithFormat:@"INSERT INTO attaches(name, id, path) VALUES ('%@','%@','%@')",attach.name, attach.attachID,attach.path];
    
    
    return query;

}

+(NSString*) deleteAttach: (Attach*)attach{
    NSString *query=[NSString stringWithFormat:@"DELETE FROM attaches WHERE id='%@'",attach.attachID];
    return query;
}
+(NSString*) selectAttach: (Attach*)attach{
    NSString *query=[[@"SELECT name FROM attaches WHERE id =\"" stringByAppendingString:attach.attachID]stringByAppendingString:@"\""];
    return query;

}

@end
